import React from "react"

import { PageType } from "@/api/business/types"
import http from "@/api/helper/request"

import { IQueryItemDetailParams, IQueryListParams, IResponseItem, IResponseItemDetail } from "./types"

const useApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined, config: object = {}) {
		setLoading(true)
		let ret = await http.post<T>(url, body, config)
		setLoading(false)
		return ret
	}

	const getList = (body?: IQueryListParams & PageType) =>
		generalHttp<Business.TableResourceType<IResponseItem>>("/memberFundsRecords/memberArtificialAddAuditRecord", body)

	const getDetail = (body?: IQueryItemDetailParams) =>
		generalHttp<IResponseItemDetail>("/memberArtificialPatchAccountAdd/auditDetail", body)

	return {
		loading,
		generalHttp,
		getList,
		getDetail
	}
}

export default useApi
